function serializeTable(val, name, skipnewlines, depth)
    skipnewlines = skipnewlines or true
    depth = depth or 0
    local tmp = string.rep("", depth)
    if name then
        if type(name) == "number" then
            tmp = tmp .. '[' .. name .. "]="
        else
            if string.byte(name, 1, 1) < 58 and string.byte(name, 1, 1) > 47 then
                tmp = tmp .. string.format("[\"%s\"]=", name) --不要用\',这样就存不进数据库了,因为又有'号双有"号数据库语句识别不了
            else
                tmp = tmp .. name .. "="
            end
        end
    end
    if type(val) == "table" then
        tmp = tmp .. "{" .. (not skipnewlines and "\n" or "")
        for k, v in pairs(val) do
            tmp = tmp .. serializeTable(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "")
        end
        tmp = tmp .. string.rep("", depth) .. "}"
    elseif type(val) == "number" then
        tmp = tmp .. tostring(val)
    elseif type(val) == "string" then
        tmp = tmp .. string.format("%q", val)
    elseif type(val) == "boolean" then
        tmp = tmp .. (val and "true" or "false")
    else
        tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\""
    end
    return tmp
end

function writefile(text, mod)
    if not mod then mod = "a+" end
    local now = os.date("*t", os.time())
    local foldername = string.format("%d_%02d_%02d.txt", now.year, now.month, now.day)
    local file = io.open(PROJ_ROOT .. "/log/" .. foldername, mod)
    if file then
        file:write(text .. "\n")
        -- file:flush()
        file:close()
    end
end

function log(...)
    if not LOG then return end
    local arg = { ... }
    local tem = os.date("%Y-%m-%d %H:%M:%S", os.time()) .. "  :";
    local j = 1;
    for i, v in pairs(arg) do
        if j < i then --判定中间是否有空值
            for k = j + 1, i do tem = tem .. "nil  "; end
            j = i;
        end
        if type(v) == 'table' then
            tem = tem .. serializeTable(v) .. "  ";  --table2str(v);--serializeTable(v)--
        else
            if v == "" then
                tem = tem .. "\"\"  ";
            else
                tem = tem .. tostring(v) .. "  ";
            end
        end
        j = j + 1;
    end
    print("tmp = ", tem);
    if tem then writefile(tem) end
    --skynet.error(tem);
end

function warn(...) log("****Warn***:", ...) end
